import configparser
from config.config import mysql_ini_path, message_ini_path,environment_ini_path

# 单例模式
# 该类属于文件操作的类，在读取mysql配置文件，消息通知文件都会使用到
# 可以考虑使用单例模式
class GetConfig:
    def __init__(self):
        self.cfg = configparser.ConfigParser()

    def get_database_data(self):
        """获取mysql所有的节点和值"""
        self.cfg.read(mysql_ini_path, encoding="utf-8")
        # 如果想要使用这种方式，保证必须是[0]
        data = dict(self.cfg.items("mysql"))
        data["port"] = int(data["port"])
        return data


    def get_message_dingding(self):
        """获取钉钉消息通知相关的配置"""
        self.cfg.read(message_ini_path, encoding="utf-8")
        data = dict(self.cfg.items("dingding"))
        return data

    def get_message_wechat(self):
        """获取企业微信消息通知相关配置"""
        self.cfg.read(message_ini_path, encoding="utf-8")
        data = dict(self.cfg.items("wechat"))
        data["headers"] = eval(data["headers"])
        return data

    def get_message_email(self):
        """获取邮箱通知相关配置"""
        self.cfg.read(message_ini_path, encoding="utf-8")
        data = dict(self.cfg.items("email"))
        data["recipients"] = eval(data["recipients"])
        return data

    def get_message_report_path(self):
        """获取消息通知报告路径相关配置"""
        self.cfg.read(message_ini_path, encoding="utf-8")
        data = dict(self.cfg.items("report"))
        return data

    def get_base_url(self):
        """获取基础的不同的环境的url"""
        self.cfg.read(environment_ini_path, encoding="utf-8")
        data = dict(self.cfg.items("test_base_url"))
        return data.get("base_url")


if __name__ == '__main__':
    c1 = GetConfig()
    # print(c1.get_database_data())

    print(c1.get_message_report_path())

    print(c1.get_message_dingding())

    print(c1.get_message_wechat())

    print(c1.get_message_email())